#!/bin/bash
#
# Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
#

set -ex
CURRENT_PATH=$(cd $(dirname $0);pwd)
LOG_FILE=${CURRENT_PATH}/package_asset.log
function log() {
    level=$1
    info=$2
    time=$(date '+%Y-%m-%d %H:%M:%S')
    echo "${time} [${level}]: ${info}" >> ${LOG_FILE}
}

CONFIG_PATH=${CURRENT_PATH}/package_config.conf
source ${CONFIG_PATH}
TMP_DIR=${CURRENT_PATH}/$(date +%s)
if [[ -d ${TMP_DIR} ]]; then
    log "error" "${TMP_DIR} exists"
    echo "package failed, ${TMP_DIR} exists"
    exit 1
fi
asset_name=$(echo ${asset_name} | awk -F '-' '{print $2}')
mkdir -p ${TMP_DIR}/${asset_name}
mkdir -p ${TMP_DIR}/assets
cd ${CURRENT_PATH}/${item_dir} && zip -r ${TMP_DIR}/${asset_name}/${item_dir}.zip ./* || exit 1
cd ${CURRENT_PATH}/${scene_dir} && zip -r ${TMP_DIR}/${asset_name}/${scene_dir}.zip ./* || exit 1
cd ${TMP_DIR}/${asset_name}
zip -r ${TMP_DIR}/assets/${asset_name}.zip ./* || exit 1
rm -rf ${TMP_DIR}/${asset_name}
cd ${TMP_DIR}
zip -r ${CURRENT_PATH}/${asset_name}.zip assets || exit 1
echo "package successfully,please delete ${TMP_DIR} manually"

